package com.aree.caipiao.model;

import java.io.Serializable;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.springframework.util.StringUtils;

@MappedSuperclass
public abstract class IdEntity implements Serializable {
	private static final long serialVersionUID = 7778264995107297640L;

	protected Long id;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Transient
	protected String getTabelName() {
		Table table = this.getClass().getAnnotation(Table.class);
		if (table != null) {
			String tableName = table.name();
			if (StringUtils.hasLength(tableName)) {
				return tableName;
			}
		}
		return this.getClass().getSimpleName();
	}
}
